
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>带摇晃特效的扁平风格登录注册表单界面</title>
    <link rel="stylesheet" type="text/css" href="../static/css/login.css">
</head>
<body>
<p class="title">东软试题库管理系统</p>
<div id="wrapper" class="login-page">
    <div id="login_form" class="form">
        <form class="register-form">
            <input type="text" placeholder="教师编号" id="r_user_id" />
            <input type="text" placeholder="用户名" id="r_user_name" />
            <input type="password" placeholder="密码（20个字符以内）" id="r_password" />
            <input type="text" placeholder="专业名称" id="r_discipline" />
            <input type="text" placeholder="电子邮件" id="r_mail" />
            <button id="create">创建账户</button>
            <p class="message">已经有了一个账户? <a href="#">立刻登录</a></p>
        </form>
        <form class="login-form">
            <h2 style="text-align: center" ><font size="6px">教师登录</font></h2><br>
            <input type="text" placeholder="教师编号" id="user_id"/>
            <input type="password" placeholder="密码" id="password" />
            <button id="login">登　录</button>
            <p class="message">还没有账户? <a href="#">立刻创建</a></p>
            <p class="message"><font size="2px">忘记密码请联系管理员进行找回 </font></a></p>
            <p class="message"><font size="2px" color="gray">———————其他类型用户登录入口———————</font></a></p>
            <p class="message"><a href="studentlogin">学生登录入口</a>&emsp;&emsp;&emsp;&emsp;<a href="managerlogin">管理登录入口</a></p>
        </form>
    </div>
</div>

<script src="../static/js/jquery.min.js"></script>
<script type="text/javascript">
    function check_login() {
        console.log('suck');
        var id=$("#user_id").val();
        var pwd=$("#password").val();
        console.log(pwd);
        $.ajax({
            url: "teacher/login",
            type : "post",
            async: false,
            dataType: "json",
            data :{ teaNo: id, teaPwd: pwd},

            success: function (data) {
                console.log("请求成功");
                console.log(data);
                if(data.toString() === "true") {
                    window.location.href = 'teacher';
                    sessionStorage.setItem("teaId", id);
                }
                if(data.toString() === "false")
                {
                    $("#login_form").removeClass('shake_effect');
                    setTimeout(function()
                    {
                        $("#login_form").addClass('shake_effect')
                    },1);
                }
                return;
            },
            error: function (data) {
                console.log("请求失败");
                $("#login_form").removeClass('shake_effect');
                setTimeout(function()
                {
                    $("#login_form").addClass('shake_effect')
                },1);
                return;
            }
        });
        return ;
    }
    function check_register(){
        var id = $("#r_user_id").val();
        var pass = $("#r_password").val();
        var name = $("#r_user_name").val();
        var discipline = $("#r_discipline").val();
        var mail = $("#r_mail").val();
        var teacher = {teaNo:id,teaName:name,teaPwd:pass,teaDiscipline:discipline,teaMail:mail};

        console.log("shit");
        console.log(JSON.stringify(teacher));
        $.ajax({
            url: "teacher/add",
            type : "post",
            async: false,
            dataType: "json",
            data :JSON.stringify(teacher),
            contentType :"application/json",
            success: function (data) {
                console.log("请求成功");
                console.log(data);
                if(data === 1) {window.location.href = 'teacherlogin';}
                if(data === 0)
                {

                    $("#login_form").removeClass('shake_effect');
                    setTimeout(function()
                    {
                        $("#login_form").addClass('shake_effect')
                    },1);
                }
                return;
            },
            error: function (data) {
                console.log("编号重复");
                $("#login_form").removeClass('shake_effect');
                setTimeout(function()
                {
                    $("#login_form").addClass('shake_effect')
                },1);
                return;
            }
        });
    }
    $(function(){
        $("#create").click(function(){
            check_register();
            return false;
        })
        $("#login").click(function(){
            check_login();
            return false;
        })
        $('.message a').click(function () {
            $('form').animate({
                height: 'toggle',
                opacity: 'toggle'
            }, 'slow');
        });
    })
</script>
</body>
</html>